def isPrime(number)
    if number <= 1
        return false
    elsif number == 2
        return true
    else
        (2..Math.sqrt(number).floor).each do |divisor|
            if number.modulo(divisor) == 0
                return false
            end
        end

    end
    true
end

def truncateLeft(number)
    array = []
    numberString = number.to_s
    (0..numberString.length - 1).each do |counter|
        array.push numberString[counter, numberString.length].to_i
    end
    array
end

def truncateRight(number)
    array = []
    numberString = number.to_s
    (numberString.length).downto(1) do |counter|
        array.push numberString[0, counter].to_i
    end
    array
end

keepers = []
counter = 10
sum = 0
while keepers.length < 11
    numbers = truncateLeft(counter) + truncateRight(counter)
    allPrime = true
    numbers.each do |number|
        if !isPrime number
            allPrime = false
            break
        end
    end
    if allPrime
        keepers.push counter
        sum = sum + counter
        puts counter.to_s + " " + sum.to_s
    end
    counter = counter + 1
end